package com.ruoyi.crm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.crm.domain.CrmProjectWork;
import com.ruoyi.crm.service.ICrmProjectWorkService;
import com.taobao.api.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目维保工作日志Controller
 *
 * @author yanwenliang
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/crm/work")
public class CrmProjectWorkController extends BaseController
{
    @Autowired
    private ICrmProjectWorkService crmProjectWorkService;

    /**
     * 查询项目维保工作日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CrmProjectWork crmProjectWork)
    {
        startPage();
        List<CrmProjectWork> list = crmProjectWorkService.selectCrmProjectWorkList(crmProjectWork);
        return getDataTable(list);
    }

    /**
     * 导出项目维保工作日志列表
     */
    @Log(title = "项目维保工作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmProjectWork crmProjectWork)
    {
        List<CrmProjectWork> list = crmProjectWorkService.selectCrmProjectWorkList(crmProjectWork);
        ExcelUtil<CrmProjectWork> util = new ExcelUtil<CrmProjectWork>(CrmProjectWork.class);
        util.exportExcel(response, list, "项目维保工作日志数据");
    }

    /**
     * 获取项目维保工作日志详细信息
     */
    @GetMapping(value = "/{workId}")
    public AjaxResult getInfo(@PathVariable("workId") String workId)
    {
        return AjaxResult.success(crmProjectWorkService.selectCrmProjectWorkByWorkId(workId));
    }

    /**
     * 新增项目维保工作日志
     */
    @Log(title = "项目维保工作日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmProjectWork crmProjectWork) throws ApiException {
        return toAjax(crmProjectWorkService.insertCrmProjectWork(crmProjectWork));
    }

    /**
     * 修改项目维保工作日志
     */
    @Log(title = "项目维保工作日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmProjectWork crmProjectWork)
    {
        return toAjax(crmProjectWorkService.updateCrmProjectWork(crmProjectWork));
    }

    /**
     * 删除项目维保工作日志
     */
    @Log(title = "项目维保工作日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workIds}")
    public AjaxResult remove(@PathVariable String[] workIds)
    {
        return toAjax(crmProjectWorkService.deleteCrmProjectWorkByWorkIds(workIds));
    }
}
